package com.ohs.ohsoa.system.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.MeetingpersonsDto;
import com.ohs.ohsoa.system.service.MeetingpersonsService;
import com.ohs.ohsoa.system.vo.MeetingpersonsVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 *会议参与者
 *
 * @author qhuang
 * @since 2021-11-11
 */
@Api(value = "会议参与者controller", tags = "会议参与者")
@RestController
@RequestMapping(value = "/meetingpersons")
public class MeetinngpersonsController {

    @Resource
    private MeetingpersonsService meetingpersonsService;

    /**
     * 获取我的会议列表信息
     * @param pageParam 检索用信息
     * @return 我的会议列表信息
     */
    @UserLoginToken
    @PostMapping(value = "/select/list/byid")
    @ApiOperation(httpMethod = "POST", value = "获取我的会议列表信息")
    public ResultBean<PageInfo<MeetingpersonsVo>> meetingSelectListByUserid(@RequestBody PageParam<MeetingpersonsDto> pageParam){
        List<MeetingpersonsVo> res = meetingpersonsService.meetingSelectListByUserid(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }

    /**
     * 我需要参加并且未读的会议
     * @param meetingpersonsDto 我的会议数据
     * @return 我需要参加并且未读的会议
     */
    @UserLoginToken
    @PostMapping(value = "/select/count")
    @ApiOperation(httpMethod = "POST", value = "我需要参加并且未读的会议")
    public ResultBean<Integer> meetingSelectCountIndex(@RequestBody MeetingpersonsDto meetingpersonsDto){
        return ResultBean.success(meetingpersonsService.meetingSelectCountIndex(meetingpersonsDto));
    }

    /**
     * 更新会议参与已读
     * @param meetingpersonsDto 我的会议数据
     * @return 会议参与已读
     */
    @UserLoginToken
    @PutMapping(value = "/update/read")
    @ApiOperation(httpMethod = "PUT", value = "更新会议参与已读")
    public ResultBean<Boolean> meetingpersonsUpdateRead(@RequestBody MeetingpersonsDto meetingpersonsDto){

        String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        meetingpersonsDto.setMpReadtime(nowTime);
        return ResultBean.success(meetingpersonsService.meetingpersonsUpdateRead(meetingpersonsDto));
    }

    /**
     * 更新会议是否参与
     * @param meetingpersonsDto 我的会议数据
     * @return 会议是否参与
     */
    @UserLoginToken
    @PutMapping(value = "/update/join")
    @ApiOperation(httpMethod = "PUT", value = "更新会议是否参与")
    public ResultBean<Boolean> meetingpersonsUpdateJoin(@RequestBody @Valid MeetingpersonsDto meetingpersonsDto, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        meetingpersonsDto.setMpSuretime(nowTime);
        return ResultBean.success(meetingpersonsService.meetingpersonsUpdateJoin(meetingpersonsDto));
    }

}
